package com.security.sm2;

import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.SM2;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class HTSM2 {

    public static void main(String[] args) {
        String msg = "unm2K10";
        SM2 sm2 = SmUtil.sm2(Base64.getDecoder().decode(SM2Util.pr1), Base64.getDecoder().decode(SM2Util.pu1));

        String jia = Base64.getEncoder().encodeToString(sm2.encrypt(msg.getBytes(StandardCharsets.US_ASCII), KeyType.PublicKey));

//        jia = "MHACIQCNYoCBAKFeSsIwtyAerXw8XFEcRtgsSnRkD2GqWNIFhgIgdavtnrMmQ5jQMxc3gc2+aL5OuVr4RLz1GEDHB4xH6kQEIP/jlT/kQ80adAxKCVIgsuZLcgYPnYpcUuqwhfte4fYeBAfS1aO1Vo+7";
        String jie = new String(sm2.decrypt(Base64.getDecoder().decode(jia), KeyType.PrivateKey));
        //BA52Rr+tUuSEhyWXXKik9yoL0RsybPPFg+9XSMF1FZgIQpbsXKU5PBUjuDSTIwpjgqUmLabTT8i7F11tEm6M8hBxo6g1Ggv9IX7xQdRgUZm/zDBBPj7GpCEdXMJbk8p1W2U3zi0ttkE=
        System.out.println("加密后：" + jia);
        System.out.println("解密后：" + jie);
    }
}
